package com.sanley.coronavirus.controller;

import com.github.pagehelper.PageInfo;
import com.sanley.coronavirus.common.api.CommonResult;
import com.sanley.coronavirus.entity.Cure;
import com.sanley.coronavirus.entity.User;
import com.sanley.coronavirus.service.CureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/cure")
@Api(value = "CureController", description = "治愈管理")
public class CureController {
    @Autowired
    CureService service;

    //所有治愈者
    @ApiOperation("所有治愈者")
    @GetMapping(value = "list")
    @ResponseBody
    public CommonResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                             @RequestParam(name = "size", defaultValue = "25") int size,
                             @RequestParam(name = "keyword", required = false) String keyword) {
        List<Cure> cures = null;
        if (keyword != null && keyword.trim().length() != 0) {
            cures = service.findByName(keyword);
        } else {
            cures = service.findAll(page, size);
        }
        PageInfo<User> pageInfo = new PageInfo(cures);
        return CommonResult.success(pageInfo);
    }

}
